<template>
  <div class="custom-field-tab">
    <div class="operation-bar">
      <!-- 操作按钮区域 -->
      <action-buttons
          :buttons="buttonsConfig"
          @viewLog="handleViewLog"
      />
      <button class="custom-action-btn">
        <el-icon class="icon-class"><Finished /></el-icon>
        <span>保存</span>
      </button>
    </div>
    <div class="main-content">
      <!-- 自定义字段表格 -->
      <div class="custom-field-box" v-for="(item, index) in columnsData" :key="index">
        <div class="field-content">
          <div class="field-row">
            <div class="field-label">自定义{{ index }}</div>
            <el-input v-model="item.fieldName" placeholder="显示名称" class="field-input"/>
            <el-checkbox v-model="item.isEnabled" label="启用"/>
          </div>
          <div class="field-row format-row">
            <div class="field-label">格式</div>
            <el-select v-model="item.fieldFormat" class="field-input">
              <el-option label="文本" value="text"/>
              <el-option label="数字" value="number"/>
              <el-option label="时间" value="datetime"/>
            </el-select>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import {ref} from 'vue'
import {ElMessage} from 'element-plus'
import ActionButtons from "@/components/action-buttons/action-buttons.vue";

// 操作按钮配置
const buttonsConfig = ref({
  add: {visible: false, order: 1, type: 'success'},
  edit: {visible: false, order: 2},
  delete: {visible: false, order: 3, type: 'danger'},
  import: {visible: false, order: 4},
  export: {visible: false, order: 5},
  viewLog: {visible: true, order: 6},
  enable: {visible: false, order: 2},
  disable: {visible: false, order: 3},
})
// 操作按钮事件
const handleViewLog = () => {
  ElMessage.success('点击了日志按钮')
}


const columnsData = ref([
  {
    fieldName: '',
    isEnabled: false,
    fieldFormat: ''
  },
  {
    fieldName: '',
    isEnabled: false,
    fieldFormat: ''
  },
  {
    fieldName: '',
    isEnabled: false,
    fieldFormat: ''
  },
  {
    fieldName: '',
    isEnabled: false,
    fieldFormat: ''
  },
  {
    fieldName: '',
    isEnabled: false,
    fieldFormat: ''
  },
  {
    fieldName: '',
    isEnabled: false,
    fieldFormat: ''
  },
  {
    fieldName: '',
    isEnabled: false,
    fieldFormat: ''
  },
  {
    fieldName: '',
    isEnabled: false,
    fieldFormat: ''
  },
  {
    fieldName: '',
    isEnabled: false,
    fieldFormat: ''
  },
  {
    fieldName: '',
    isEnabled: false,
    fieldFormat: ''
  },
  {
    fieldName: '',
    isEnabled: false,
    fieldFormat: ''
  },
  {
    fieldName: '',
    isEnabled: false,
    fieldFormat: ''
  },
  {
    fieldName: '',
    isEnabled: false,
    fieldFormat: ''
  },
  {
    fieldName: '',
    isEnabled: false,
    fieldFormat: ''
  },
  {
    fieldName: '',
    isEnabled: false,
    fieldFormat: ''
  },
  {
    fieldName: '',
    isEnabled: false,
    fieldFormat: ''
  },
  {
    fieldName: '',
    isEnabled: false,
    fieldFormat: ''
  },
  {
    fieldName: '',
    isEnabled: false,
    fieldFormat: ''
  },
  {
    fieldName: '',
    isEnabled: false,
    fieldFormat: ''
  },
  {
    fieldName: '',
    isEnabled: false,
    fieldFormat: ''
  },
  {
    fieldName: '',
    isEnabled: false,
    fieldFormat: ''
  },
])
</script>

<style scoped lang="scss">
.custom-field-tab {
  height: 100%;

  .operation-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: flex-start;

    .icon-class {
      color: var(--action-btn-icon-color);
    }
  }

  .main-content {
    display: flex;
    flex-wrap: wrap;
    gap: 20px;
    overflow-y: auto;
    max-height: 90%;
    align-items: flex-start;

    .custom-field-box {
      border: 1px solid #e4e7ed;
      border-radius: 4px;
      padding: 16px;
      background-color: #fff;
      width: 380px;
      height: 120px;
    }

    .field-content {
      display: flex;
      flex-direction: column;
      gap: 12px;
    }

    .field-row {
      display: flex;
      align-items: center;
    }

    .field-label {
      font-size: 14px;
      margin-right: 10px;
      width: 60px;
    }

    .field-input {
      width: 200px;
      margin-right: 20px;
    }

    .format-row {
      margin-top: 4px;
    }
  }
}
</style> 